//
//  OrderTableViewCell.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/7/15.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "OrderTableViewCell.h"
#import "UIButton+LayoutEdgeInsets.h"
#import "Tool+PsychologicalCounselling.h"

@interface OrderTableViewCell()
{
    Order *_order;
}
@property(nonatomic,strong)Order *order;

@end

@implementation OrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.detailsBtn roundedCorners:3];
    [self.detailsBtn setBackgroundColor:k65ACFE];
    
    [self.recordsBtn roundedCorners:3];
    [self.recordsBtn setBackgroundColor:k65ACFE];
    
    [self.detailsBtn layoutImageToRight:2];
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UITapGestureRecognizer *zer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(psuhPersonalDetails)];
    [self.headPortrait addGestureRecognizer:zer];
}

-(void)psuhPersonalDetails
{
    self.touchHeadPortrait(self);
}

- (IBAction)pushDetails:(id)sender {
    self.touchCheckDetails(self);
}

- (IBAction)medicalRecordsAction:(id)sender {
    self.touchCurriculumVitae(self);
}

-(void)setOrder:(Order *)order type:(OrderType)type
{
    _order = order;
    
    [self.headPortrait sd_setImageWithURL:[NSURL URLWithString:order.user_avatar] placeholderImage:[UIImage imageNamed:@"My_TheDefaultAvatar"]];
    self.title.text = [NSString stringWithFormat:@"%@  %d岁  %@",order.nickname,order.age,order.sex?@"女":@"男"];
    self.line.hidden = self.order.spread?NO:YES;
    self.describe.object = order;
    
    self.bookingNo.text = [NSString stringWithFormat:@"预约号: %@",order.out_trade_no];
    self.pay.text = [NSString stringWithFormat:@"%@ %.0f",order.is_pay?@"已支付":@"未支付",order.total_fee];
    self.createdTime.text = [NSString stringWithFormat:@"下单时间: %@",order.created_at];
    
    if (order.is_pay) {
        self.detailsBtn.enabled = YES;
        self.applyForBtn.enabled = YES;
        self.pay.hidden = NO;
        
        self.payInformation.text = [NSString stringWithFormat:@"订单状态: 预约%@咨询%d次 剩余%d次",[Tool TypeString:type],order.count,order.surplus_count];
        
        if (order.allow_check) {
            [self.applyForBtn setTitle:@"查看咨询履历" forState:(UIControlStateNormal)];
            
//            //已完成禁用button
//            self.applyForBtn.enabled = order.surplus_count;
            
        }else{
            [self.applyForBtn setTitle:@"申请查看咨询履历" forState:(UIControlStateNormal)];
            self.applyForBtn.enabled = order.allow_send_check;
        }
        
    }else{
        self.detailsBtn.enabled = NO;
        self.applyForBtn.enabled = NO;
        self.pay.hidden = YES;
        
        self.payInformation.text = @"订单状态: 等待支付";
    }
    
}

-(Order *)order
{
    return _order;
}

@end
